<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2020/2/13
 * Time: 14:39
 */

namespace app\admin\controller;


use think\Db;
use think\Request;

class Store extends Base
{
    /**
     * 首页
     */
    public function index(){
        if(request()->isAjax()){
            extract(input());
            $where = [];
            if(isset($user_name) && $user_name != ''){
                $where['s_name|s_address|s_phone'] = ['like', '%' . $user_name . '%'];
            }
            if(isset($typeid) && $typeid != ''){
                $where['pp_t_id'] = $typeid;
            }
            if(isset($s_pp_id) && $s_pp_id != ''){
                $where['s_pp_id'] = $s_pp_id;
            }
            if(isset($s_p_id) && $s_p_id != ''){
                $where['s_p_id'] = $s_p_id;
            }
            if(isset($s_qu) && $s_qu != ''){
                $where['s_qu'] = $s_qu;
            }
            if(isset($indexindex) && $indexindex != "")
            {
                $where['s_index'] = $indexindex;
            }
            if(isset($indexindex2) && $indexindex2 != "")
            {
                $where['s_index2'] = $indexindex2;
            }
            if(isset($indexindex3) && $indexindex3 != "")
            {
                $where['s_index3'] = $indexindex3;
            }
            if(isset($indexindex4) && $indexindex4 != "")
            {
                $where['s_index4'] = $indexindex4;
            }
            if(isset($indexindex5) && $indexindex5 != "")
            {
                $where['s_index5'] = $indexindex5;
            }

            if(isset($s_star) && $s_star != "")
            {
                $where['s_star'] = $s_star;
            }
            if(isset($s_status) && $s_status != "")
            {
                $where['s_status'] = $s_status;
            }
            if(session('agid') == 10){
                $where['s_pp_id'] = session('uid');
            }
            $NowPage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::table('up_store s')
                ->join('up_pp pp', 's.s_pp_id = pp.pp_id', 'left')
                ->join('up_place p', 's.s_p_id = p.p_id', 'left')
                ->where($where)
                ->count();// 获取总条数
            $field = 's.*,pp_name,p_name,district';
            $lists = Db::table('up_store s')
                ->join('up_area a', 's.s_qu = a.district_id', 'left')
                ->join('up_pp pp', 's.s_pp_id = pp.pp_id', 'left')
                ->join('up_place p', 's.s_p_id = p.p_id', 'left')
                ->field($field)
                ->where($where)
                ->page($NowPage,$limits)
                ->order('s_sort desc,s_time desc')
                ->select();
            if($lists){
                foreach ($lists as $k=>$v){
                    if($v['s_two_pic']){
                        $lists[$k]['s_two_pic'] = explode(',',$v['s_two_pic']);
                    }
                }
            }
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $types = Db::table('up_types')
            ->field('t_id,t_name')
            ->order('t_sort desc')
            ->select();
        $qus = Db::table('up_area')
            ->where('pid',108)
            ->field('district_id,district')
            ->select();
        $pps = Db::table('up_pp')
            ->field('pp_id,pp_name')
            ->order('pp_sort desc')
            ->select();
        $ps = Db::table('up_place')
            ->field('p_id,p_name')
            ->order('p_sort desc')
            ->select();
        $this->assign('types',$types);
        $this->assign('qus',$qus);
        $this->assign('pps',$pps);
        $this->assign('ps',$ps);
        $about_content = Db::table('up_about')->where('id','in','7,27,28,33,34')->column('content');
        $this->assign('wenan',$about_content);
        return $this->fetch();
    }
    public function getDatas()
    {
        $t_id = input('param.t_id');
        $type = input('param.type');
        if(isset($type) && $type == 1 && !$t_id){
            $data = Db::table('up_pp')
                ->field('pp_id,pp_name')
                ->order('pp_sort desc')
                ->select();
        }else {
            $data = Db::table('up_pp')
                ->where('pp_t_id', $t_id)
                ->field('pp_id,pp_name')
                ->order('pp_sort desc')
                ->select();
        }
        return json(['code'=>200,'msg'=>$data]);
    }
    /**
     * 添加
     * @return mixed|\think\response\Json
     */
    public function newAdd(){
        if(Request::instance()->isPost()){
            extract(input());
            if(session('agid') == 10){
                $s_pp_id = session('uid');
            }
            $data = [
                's_name' => $s_name,
                's_daohang' => $s_daohang,
                's_pp_id' => $s_pp_id,
                's_p_id' => $s_p_id,
                's_qu' => $s_qu,
                's_two_pic' => $s_two_pic,
                's_coupon1' => $s_coupon1,
                's_coupon2' => $s_coupon2,
                's_coupon3' => $s_coupon3,
                's_coupon4' => $s_coupon4,
                's_yongjin1' => $s_yongjin1,
                's_yongjin2' => $s_yongjin2,
                's_yongjin3' => $s_yongjin3,
                's_yongjin4' => $s_yongjin4,
                's_address' => $s_address,
                's_open' => $s_open,
//                's_star' => $s_star,
                's_phone' => $s_phone,
//                's_sort' => $s_sort,
                's_time' => date('Y-m-d H:i:s')
            ];
            if(session('agid') != 10){
                $data['s_star'] = $s_star;
                $data['s_sort'] = $s_sort;
            }
            $lonlat = explode(',',$lonlat);
            $data['s_lat'] = $lonlat[0];
            $data['s_lon'] = $lonlat[1];
            $res = Db::table('up_store')->insert($data);
            if($res){
                return json(['code' => 200, 'msg' => '添加成功']);
            }else{
                return json(['code' => 100, 'msg' => '添加失败']);
            }
        }
        $types = Db::table('up_types')
            ->field('t_id,t_name')
            ->order('t_sort desc')
            ->select();
        $qus = Db::table('up_area')
            ->where('pid',108)
            ->field('district_id,district')
            ->select();
        $pps = Db::table('up_pp')
            ->field('pp_id,pp_name')
            ->order('pp_sort desc')
            ->select();
        $ps = Db::table('up_place')
            ->field('p_id,p_name')
            ->order('p_sort desc')
            ->select();
		$sss = Db::table('up_store')
            ->field('s_address')
            ->order('s_sort desc')
            ->select();
        $this->assign('types',$types);
        $this->assign('qus',$qus);
        $this->assign('pps',$pps);
        $this->assign('ps',$ps);
        $this->assign('sss',$sss);
        return $this->fetch('store/newadd');
    }
    /**
     * 编辑
     * @return mixed
     */
    public function newEdit(){
        if(Request::instance()->isPost()){
            extract(input());
            if(session('agid') == 10){
                $s_pp_id = session('uid');
            }
            $data = [
                's_name' => $s_name,
                's_daohang' => $s_daohang,
                's_pp_id' => $s_pp_id,
                's_p_id' => $s_p_id,
                's_qu' => $s_qu,
                's_two_pic' => $s_two_pic,
                's_coupon1' => $s_coupon1,
                's_coupon2' => $s_coupon2,
                's_coupon3' => $s_coupon3,
                's_coupon4' => $s_coupon4,
                's_yongjin1' => $s_yongjin1,
                's_yongjin2' => $s_yongjin2,
                's_yongjin3' => $s_yongjin3,
                's_yongjin4' => $s_yongjin4,
                's_address' => $s_address,
                's_open' => $s_open,
//                's_star' => $s_star,
                's_phone' => $s_phone,
//                's_sort' => $s_sort,
                's_time' => date('Y-m-d H:i:s')
            ];
            if(session('agid') != 10){
                $data['s_star'] = $s_star;
                $data['s_sort'] = $s_sort;
            }
            $lonlat = explode(',',$lonlat);
            $data['s_lat'] = $lonlat[0];
            $data['s_lon'] = $lonlat[1];
            $res = Db::table('up_store')->where('s_id',$s_id)->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功']);
            }else{
                return json(['code' => 100, 'msg' => '失败']);
            }
        }
        $s_id = input('s_id');
        $info = Db::name('store')
            ->where('s_id',$s_id)
            ->find();
        $typeid = Db::name('pp')
            ->where('pp_id',$info['s_pp_id'])
            ->value('pp_t_id');
        $types = Db::table('up_types')
            ->field('t_id,t_name')
            ->order('t_sort desc')
            ->select();
        $qus = Db::table('up_area')
            ->where('pid',108)
            ->field('district_id,district')
            ->select();
        $pps = Db::table('up_pp')
            ->where('pp_t_id',$typeid)
            ->field('pp_id,pp_name')
            ->order('pp_sort desc')
            ->select();
        $ps = Db::table('up_place')
            ->field('p_id,p_name')
            ->order('p_sort desc')
            ->select();
		$sss = Db::table('up_store')
            ->field('s_address')
            ->order('s_sort desc')
            ->select();
        $this->assign('types',$types);
        $this->assign('qus',$qus);
        $this->assign('pps',$pps);
        $this->assign('ps',$ps);
        $this->assign('sss',$sss);
        $this->assign('info',$info);
        $this->assign('typeid',$typeid);
        return $this->fetch('store/newedit');
    }
    
    /**
     * 删除
     * @return \think\response\Json
     */
    public function newDel(){
        $new_id = input('id');
        $res = Db::table('up_store')->where('s_id',$new_id)->delete();
        if($res){
            return json(['code' => 200, 'msg' => '删除成功']);
        }else{
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }
    /**
     * 推荐
     * @return \think\response\Json
     */
    public function indexshow(){
        if(session('agid') == 10){
            return json(['code' => 100, 'msg' =>' 您无权冻结']);
        }
        $id = input('id');
        $param = [
            's_index'=>input('num'),
        ];
        $res = Db::name('store')->where('s_id',$id)->update($param);
        if($res){
            return json(['code' => 200, 'msg' => '修改成功']);
        }else{
            return json(['code' => 100, 'msg' =>' 修改失败']);
        }
    }
    /**
     * 推荐
     * @return \think\response\Json
     */
    public function indexshow2(){
        if(session('agid') == 10){
            return json(['code' => 100, 'msg' =>' 您无权冻结']);
        }
        $id = input('id');
        $param = [
            's_index2'=>input('num'),
        ];
        $res = Db::name('store')->where('s_id',$id)->update($param);
        if($res){
            return json(['code' => 200, 'msg' => '修改成功']);
        }else{
            return json(['code' => 100, 'msg' =>' 修改失败']);
        }
    }
    /**
     * 推荐
     * @return \think\response\Json
     */
    public function indexshow3(){
        if(session('agid') == 10){
            return json(['code' => 100, 'msg' =>' 您无权冻结']);
        }
        $id = input('id');
        $param = [
            's_index3'=>input('num'),
        ];
        $res = Db::name('store')->where('s_id',$id)->update($param);
        if($res){
            return json(['code' => 200, 'msg' => '修改成功']);
        }else{
            return json(['code' => 100, 'msg' =>' 修改失败']);
        }
    }
    /**
     * 推荐
     * @return \think\response\Json
     */
    public function indexshow4(){
        if(session('agid') == 10){
            return json(['code' => 100, 'msg' =>' 您无权冻结']);
        }
        $id = input('id');
        $param = [
            's_index4'=>input('num'),
        ];
        $res = Db::name('store')->where('s_id',$id)->update($param);
        if($res){
            return json(['code' => 200, 'msg' => '修改成功']);
        }else{
            return json(['code' => 100, 'msg' =>' 修改失败']);
        }
    }
    /**
     * 推荐
     * @return \think\response\Json
     */
    public function indexshow5(){
        if(session('agid') == 10){
            return json(['code' => 100, 'msg' =>' 您无权冻结']);
        }
        $id = input('id');
        $param = [
            's_index5'=>input('num'),
        ];
        $res = Db::name('store')->where('s_id',$id)->update($param);
        if($res){
            return json(['code' => 200, 'msg' => '修改成功']);
        }else{
            return json(['code' => 100, 'msg' =>' 修改失败']);
        }
    }
    /**
     * 排序编辑
     * @return mixed|\think\response\Json
     */
    public function updateSort(){
        $id = input('id');
        $param = [
            's_sort'=>input('value'),
        ];
        $res = Db::table('up_store')->where('s_id',$id)->update($param);
        if($res){
            return json(['code' => 200, 'msg' => '修改成功']);
        }else{
            return json(['code' => 100, 'msg' =>' 修改失败']);
        }
    }
    /**
     * 批量批量
     * @return mixed|\think\response\Json
     */
    public function ppll(){
        $id = input('id');
        $field = input('field');
        $param = [
            $field=>input('value'),
        ];
        $res = Db::table('up_store')->where('s_id','in',$id)->update($param);
        if($res){
            return json(['code' => 200, 'msg' => '修改成功']);
        }else{
            return json(['code' => 100, 'msg' =>' 修改失败']);
        }
    }
    /**
     *
     * @return \think\response\Json
     */
    public function upup(){
        $new_id = input('id');
        $res = Db::table('up_store')->where('s_id',$new_id)->setField('s_status',1);
        if($res){
            return json(['code' => 200, 'msg' => '操作成功']);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
    public function down(){
        $new_id = input('id');
        $res = Db::table('up_store')->where('s_id',$new_id)->setField('s_status',2);
        if($res){
            return json(['code' => 200, 'msg' => '操作成功']);
        }else{
            return json(['code' => 100, 'msg' => '操作失败']);
        }
    }
    //---------------------产品管理------------------------------------------------------------------
    /**
     * 产品列表
     * @return mixed|\think\response\Json
     */
    public function goods(){
        if(request()->isAjax ()){
            extract(input());
            $where = [
                'good_s_id' => ['like','%,' . session('s_id') . ',%']
            ];
            if(isset($keyword) && $keyword != ''){
                $where['good_name|st_name|spp_name|sstyle_name'] = ['like', '%' . $keyword . '%'];
            }
            if(isset($good_status) && $good_status != "")
            {
                $where['good_status'] = $good_status;
            }
            if(isset($good_t_id) && $good_t_id != "")
            {
                $where['good_t_id'] = $good_t_id;
            }
            if(isset($good_pp_id) && $good_pp_id != "")
            {
                $where['good_pp_id'] = $good_pp_id;
            }
            if(isset($good_style_id) && $good_style_id != "")
            {
                $where['good_style_id'] = $good_style_id;
            }
            $field = 'g.*,st_name,spp_name,sstyle_name';
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::table('up_store_goods')->alias('g')
                ->join('up_store_types st','g.good_t_id=st.st_id','LEFT')
                ->join('up_store_pps spp','g.good_pp_id=spp.spp_id','LEFT')
                ->join('up_store_style sstyle','g.good_style_id=sstyle.sstyle_id','LEFT')
//                ->join('up_store s','g.good_s_id=s.s_id','LEFT')
//                ->join('up_pp pp','g.good_s_pp_id=pp.pp_id','LEFT')
//                ->join('up_types t','g.good_s_t_id=t.t_id','LEFT')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::table('up_store_goods')->alias('g')
                ->join('up_store_types st','g.good_t_id=st.st_id','LEFT')
                ->join('up_store_pps spp','g.good_pp_id=spp.spp_id','LEFT')
                ->join('up_store_style sstyle','g.good_style_id=sstyle.sstyle_id','LEFT')
//                ->join('up_store s','g.good_s_id=s.s_id','LEFT')
//                ->join('up_pp pp','g.good_s_pp_id=pp.pp_id','LEFT')
//                ->join('up_types t','g.good_s_t_id=t.t_id','LEFT')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('good_sort desc,good_time desc')
                ->field($field)
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $s_id = input('s_id');
        session('s_id',$s_id);
        $datas = $this->getTypePPStyle();
        $this->assign('types',$datas[0]);
        $this->assign('pps',$datas[1]);
        $this->assign('styles',$datas[2]);
        return $this->fetch();
    }
    /**
     * 添加
     * @return mixed|\think\response\Json
     */
    public function goodAdd(){
        if(Request::instance()->isPost()){
            extract(input());
            $ppid = Db::table('up_store')->where('s_id',session('s_id'))->value('s_pp_id');
            $tid = Db::table('up_pp')->where('pp_id',$ppid)->value('pp_t_id');
            $data = [
                'good_s_id' => ','.session('s_id').',',
                'good_name' => $good_name,
                'good_s_t_id' => $tid,
                'good_s_pp_id' => $ppid,
                'good_thumb' => $good_thumb,
                'good_t_id' => $good_t_id,
                'good_pp_id' => $good_pp_id,
                'good_style_id' => $good_style_id,
                'good_money_name' => $good_money_name,
                'good_money_min' => $good_money_min,
                'good_money_max' => $good_money_max,
                'good_sort' => $good_sort,
                'good_time' => date('Y-m-d H:i:s'),
            ];
            $res = Db::table('up_store_goods')->insert($data);
            if($res){
                return json(['code' => 200, 'msg' => '添加成功']);
            }else{
                return json(['code' => 100, 'msg' => '添加失败']);
            }
        }
        $datas = $this->getTypePPStyle();
        $this->assign('types',$datas[0]);
        $this->assign('pps',$datas[1]);
        $this->assign('styles',$datas[2]);
        return $this->fetch();
    }
    /**
     * 编辑
     * @return mixed
     */
    public function goodEdit(){
        if(Request::instance()->isPost()){
            extract(input());
            $data = [
                'good_name' => $good_name,
                'good_thumb' => $good_thumb,
                'good_t_id' => $good_t_id,
                'good_pp_id' => $good_pp_id,
                'good_style_id' => $good_style_id,
                'good_money_name' => $good_money_name,
                'good_money_min' => $good_money_min,
                'good_money_max' => $good_money_max,
                'good_sort' => $good_sort,
                'good_time' => date('Y-m-d H:i:s'),
            ];
            $res = Db::table('up_store_goods')->where('good_id',$good_id)->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功']);
            }else{
                return json(['code' => 100, 'msg' => '失败']);
            }
        }
        $good_id = input('good_id');
        $info = Db::table('up_store_goods')
            ->where('good_id',$good_id)
            ->find();
        $this->assign([
            'info' => $info,
        ]);
        $datas = $this->getTypePPStyle();
        $this->assign('types',$datas[0]);
        $this->assign('pps',$datas[1]);
        $this->assign('styles',$datas[2]);
        return $this->fetch();
    }
    /**
     * 排序编辑
     * @return mixed|\think\response\Json
     */
    public function updateGoodSort(){
        $id = input('id');
        $field = input('field');
        $param = [
            $field => input('value'),
        ];
        $res = Db::table('up_store_goods')->where('good_id',$id)->update($param);
        if($res){
            return json(['code' => 200, 'msg' => '修改成功']);
        }else{
            return json(['code' => 100, 'msg' =>' 修改失败']);
        }
    }
    /**
     * 删除
     * @return \think\response\Json
     */
    public function goodDel(){
        $nt_id = input('id');
        $res = Db::table('up_store_goods')->where('good_id',$nt_id)->delete();
        if($res){
            return json(['code' => 200, 'msg' => '删除成功']);
        }else{
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }
    /**
     * 冻结启用
     * @return mixed|\think\response\Json
     */
    public function changeGoodStatus(){
        if(session('agid') == 10){
            return json(['code' => 100, 'msg' =>' 您无权冻结']);
        }
        $id = input('id');
        $param = [
            'good_status'=>input('num'),
        ];
        $res = Db::table('up_store_goods')->where('good_id',$id)->update($param);
        if($res){
            return json(['code' => 200, 'msg' => '修改成功']);
        }else{
            return json(['code' => 100, 'msg' =>' 修改失败']);
        }
    }
    /**
     * 置顶or不置顶
     * @return mixed|\think\response\Json
     */
    public function changeGoodTop(){
        if(session('agid') == 10){
            return json(['code' => 100, 'msg' =>' 您无权冻结']);
        }
        $id = input('id');
        $param = [
            'good_top'=>input('num'),
        ];
        $res = Db::table('up_store_goods')->where('good_id',$id)->update($param);
        if($res){
            return json(['code' => 200, 'msg' => '修改成功']);
        }else{
            return json(['code' => 100, 'msg' =>' 修改失败']);
        }
    }
    //-----------------------------------商品图册----------------------------------------------------------------------
    /**
     * 轮播图首页展示
     * @return mixed|\think\response\Json
     */
    public function newBanner(){
        if(request()->isAjax ()){
            extract(input());
            $where = [
                'pb_pp_id' => session('good_id')
            ];
            if(isset($keyword) && $keyword != ''){
                $where['pb_title|pb_title_up'] = ['like', '%' . $keyword . '%'];
            }
            if(isset($banner_type) && $banner_type != "")
            {
                $where['pb_type'] = $banner_type;
            }
            if(isset($pb_where) && $pb_where != "")
            {
                $where['pb_where'] = $pb_where;
            }
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('good_banner')->where($where)->count();// 获取总条数
            $lists = Db::name('good_banner')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('pb_where asc,pb_sort desc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $good_id = input('good_id');
        session('good_id',$good_id);
        return $this->fetch('store/banner');
    }
    /**
     * 添加
     * @return mixed|\think\response\Json
     */
    public function bannerAdd(){
        if(Request::instance()->isPost()){
            extract(input());
            $cpd_content1 = trim($cpd_content1,', ');
            if(!$cpd_content1){
                return json(['code' => 100, 'msg' => '上传内容不能为空！']);
            }
            $cpd_content1 = explode(',',$cpd_content1);
            $data = [];
            foreach ($cpd_content1 as $k => $v){
                $mww = [
                    'pb_title' => $pb_title,
                    'pb_pp_id' => session('good_id'),
                    'pb_type' => $pb_type,
                    'pb_sort' => $pb_sort,
                    'pb_where' => $pb_where,
                    'pb_url' => $v,
                    'pb_time' => date('Y-m-d H:i:s')
                ];
                if($pb_type == 1){
                    $mww['pb_title_up'] = $pb_title_up;
                }
                $data[] = $mww;
            }
            $res = Db::table('up_good_banner')->insertAll($data);
            if($res){
                return json(['code' => 200, 'msg' => '添加成功']);
            }else{
                return json(['code' => 100, 'msg' => '添加失败']);
            }
        }
        $type = input('type');
        $this->assign('type',$type);
        return $this->fetch('store/banneradd');
    }
    /**
     * 编辑
     * @return mixed
     */
    public function bannerEdit(){
        if(Request::instance()->isPost()){
            extract(input());
            $data = [
                'pb_title' => $pb_title,
                'pb_where' => $pb_where,
                'pb_time' => date('Y-m-d H:i:s')
            ];
            $pb_type = Db::table('up_good_banner')->where('pb_id',$pb_id)->value('pb_type');
            if($pb_type != 2){
                $data['pb_url'] = $pb_url;
            }else{
                $data['pb_url'] = $video;
            }
            if($pb_type == 1){
                $data['pb_title_up'] = $pb_title_up;
            }
            $res = Db::table('up_good_banner')->where('pb_id',$pb_id)->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功']);
            }else{
                return json(['code' => 100, 'msg' => '失败']);
            }
        }
        $pb_id = input('pb_id');
        $info = Db::name('good_banner')
            ->where('pb_id',$pb_id)
            ->find();
        $this->assign([
            'banner' => $info,
        ]);
        return $this->fetch('store/banneredit');
    }
    /**
     * 删除
     * @return \think\response\Json
     */
    public function bannerDel(){
        $nt_id = input('id');
        $res = Db::table('up_good_banner')->where('pb_id',$nt_id)->delete();
        if($res){
            return json(['code' => 200, 'msg' => '删除成功']);
        }else{
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }
    /**
     * 批量删除
     * @return \think\response\Json
     */
    public function batchDel(){
        $nt_id = input('ids');
        $res = Db::table('up_good_banner')->where('pb_id','in',$nt_id)->delete();
        if($res){
            return json(['code' => 200, 'msg' => '删除成功']);
        }else{
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }
    /**
     * 排序编辑
     * @return mixed|\think\response\Json
     */
    public function updateBannerSort(){
        $id = input('id');
        $param = [
            'pb_sort'=>input('value'),
        ];
        $res = Db::name('good_banner')->where('pb_id',$id)->update($param);
        if($res){
            return json(['code' => 200, 'msg' => '修改成功']);
        }else{
            return json(['code' => 100, 'msg' =>' 修改失败']);
        }
    }
    //-----------------------------------门店轮播图----------------------------------------------------------------------
    /**
     * 轮播图首页展示
     * @return mixed|\think\response\Json
     */
    public function newBanner1(){
        if(request()->isAjax ()){
            extract(input());
            $where = [
                'pb_pp_id' => session('s_id')
            ];
            if(isset($keyword) && $keyword != ''){
                $where['pb_title|pb_title_up'] = ['like', '%' . $keyword . '%'];
            }
            if(isset($banner_type) && $banner_type != "")
            {
                $where['pb_type'] = $banner_type;
            }
            if(isset($pb_where) && $pb_where != "")
            {
                $where['pb_where'] = $pb_where;
            }
            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 10;
            $count = Db::name('store_banner')->where($where)->count();// 获取总条数
            $lists = Db::name('store_banner')
                ->where($where)
                ->page($Nowpage,$limits)
                ->order('pb_where asc,pb_sort desc')
                ->select();
            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        $s_id = input('s_id');
        session('s_id',$s_id);
        return $this->fetch('store/banner1');
    }
    /**
     * 添加
     * @return mixed|\think\response\Json
     */
    public function bannerAdd1(){
        if(Request::instance()->isPost()){
            extract(input());
            $cpd_content1 = trim($cpd_content1,', ');
            if(!$cpd_content1){
                return json(['code' => 100, 'msg' => '上传内容不能为空！']);
            }
            $cpd_content1 = explode(',',$cpd_content1);
            $data = [];
            foreach ($cpd_content1 as $k => $v){
                $mww = [
                    'pb_title' => $pb_title,
                    'pb_pp_id' => session('s_id'),
                    'pb_type' => 1,
                    'pb_sort' => $pb_sort,
                    'pb_where' => 1,
                    'pb_url' => $v,
                    'pb_time' => date('Y-m-d H:i:s')
                ];
                $data[] = $mww;
            }
            $res = Db::table('up_store_banner')->insertAll($data);
            if($res){
                return json(['code' => 200, 'msg' => '添加成功']);
            }else{
                return json(['code' => 100, 'msg' => '添加失败']);
            }
        }
        $type = input('type');
        $this->assign('type',$type);
        return $this->fetch('store/banneradd1');
    }
    /**
     * 编辑
     * @return mixed
     */
    public function bannerEdit1(){
        if(Request::instance()->isPost()){
            extract(input());
            $data = [
                'pb_title' => $pb_title,
                'pb_time' => date('Y-m-d H:i:s')
            ];
            $data['pb_url'] = $pb_url;
            $res = Db::table('up_store_banner')->where('pb_id',$pb_id)->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功']);
            }else{
                return json(['code' => 100, 'msg' => '失败']);
            }
        }
        $pb_id = input('pb_id');
        $info = Db::name('store_banner')
            ->where('pb_id',$pb_id)
            ->find();
        $this->assign([
            'banner' => $info,
        ]);
        return $this->fetch('store/banneredit1');
    }
    /**
     * 删除
     * @return \think\response\Json
     */
    public function bannerDel1(){
        $nt_id = input('id');
        $res = Db::table('up_store_banner')->where('pb_id',$nt_id)->delete();
        if($res){
            return json(['code' => 200, 'msg' => '删除成功']);
        }else{
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }
    /**
     * 批量删除
     * @return \think\response\Json
     */
    public function batchDel1(){
        $nt_id = input('ids');
        $res = Db::table('up_store_banner')->where('pb_id','in',$nt_id)->delete();
        if($res){
            return json(['code' => 200, 'msg' => '删除成功']);
        }else{
            return json(['code' => 100, 'msg' => '删除失败']);
        }
    }
    /**
     * 排序编辑
     * @return mixed|\think\response\Json
     */
    public function updateBannerSort1(){
        $id = input('id');
        $param = [
            'pb_sort'=>input('value'),
        ];
        $res = Db::name('store_banner')->where('pb_id',$id)->update($param);
        if($res){
            return json(['code' => 200, 'msg' => '修改成功']);
        }else{
            return json(['code' => 100, 'msg' =>' 修改失败']);
        }
    }
    /**
     * 设置主页面显示
     * @return \think\response\Json
     */
    public function changeMainStatus(){
        $id = input('id');
        $param = [
            'pb_main'=>input('num'),
        ];
        $res = Db::table('up_store_banner')->where('pb_id',$id)->update($param);
        if($res){
            return json(['code' => 200, 'msg' => '修改成功']);
        }else{
            return json(['code' => 100, 'msg' =>' 修改失败']);
        }
    }
    /**
     * 设置主页面独立轮播图显示
     * @return \think\response\Json
     */
    public function changeDuliStatus(){
        $id = input('id');
        $param = [
            'pb_more'=>input('num'),
        ];
        $res = Db::table('up_store_banner')->where('pb_id',$id)->update($param);
        if($res){
            return json(['code' => 200, 'msg' => '修改成功']);
        }else{
            return json(['code' => 100, 'msg' =>' 修改失败']);
        }
    }
}